package com.xzq.message;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author xzq
 * @Description //TODO
 * @Date 2021/11/22 19:55
 * @Version 1.0.0
 **/
public abstract class Message {
    private static Map<Integer, Class<? extends Message>> messageClass = new HashMap<>();
    private  int messageType;

    public static final int PingMessage = -1;
    public static final int PongMessage = -2;

    public static final int RpcRequestMessage = 1;
    public static final int RpcResponseMessage = 2;

    static {
        messageClass.put(PingMessage,PingMessage.class);
        messageClass.put(PongMessage,PongMessage.class);
        messageClass.put(RpcRequestMessage,RpcRequestMessage.class);
        messageClass.put(RpcResponseMessage,RpcResponseMessage.class);
    }

    public static Class<? extends Message> match(int messageType) {
        return  messageClass.get(messageType);
    }

    public abstract Integer getMessageType();
}
